package org.rslai.autotest.core.page.impl;

import java.io.IOException;

import javax.mail.MessagingException;

import org.rslai.autotest.core.page.Email;
import org.rslai.util.email.IMAP;
import org.rslai.util.email.IMAPinfo;
import org.rslai.util.email.POP3;
import org.rslai.util.email.POP3info;
import org.rslai.util.email.SMTP;
import org.rslai.util.email.SMTPinfo;

/**
 * Email处理方法（SMTP、POP、IMAP协议）
 * @author rslai
 */
public class EmailImpl implements Email {
	private String smtpServerHost;
	private String pop3ServerHost;
	private String imapServerHost;
	
	public void setSmtpServerHost(String smtpServerHost) {
		this.smtpServerHost = smtpServerHost;
	}

	@Override
	public String getSmtpServerHost() {
		return this.smtpServerHost;
	}

	public void setPop3ServerHost(String pop3ServerHost) {
		this.pop3ServerHost = pop3ServerHost;
	}

	@Override
	public String getPop3ServerHost() {
		return this.pop3ServerHost;
	}

	public void setImapServerHost(String imapServerHost) {
		this.imapServerHost = imapServerHost;
	}

	@Override
	public String getImapServerHost() {
		return this.imapServerHost;
	}

	@Override
	public Boolean smtp(SMTPinfo smtpInfo) throws MessagingException {
		// 这个类主要来发送邮件
		SMTP smtp = new SMTP();
		//System.out.println( smtp.sendTextMail(smtpInfo));// 发送文体格式
		return smtp.sendHtmlMail(smtpInfo);// 发送html格式
	}

	@Override
	public Boolean pop3(POP3info pop3Info) throws MessagingException, IOException {
		POP3 pop3 = new POP3();
		return pop3.receiveAll(pop3Info); // 收取所有邮件
	}

	@Override
	public Boolean imap(IMAPinfo imapInfo) throws Exception {
		IMAP imap = new IMAP();
		return imap.receiveAll(imapInfo); // 收取所有邮件
	}

}
